﻿using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using UtilZ.Dotnet.Ex.Attributes;

namespace UtilZ.Dotnet.Ex.ValueDescription
{
    /// <summary>
    /// 值描述组
    /// </summary>
    /// <typeparam name="TValueType">值类型</typeparam>
    public class ValueDescriptionGroup<TValueType> : IValueDescriptionGroup
    {
        private readonly ConcurrentDictionary<TValueType, ConstantValueItem> _dic = new ConcurrentDictionary<TValueType, ConstantValueItem>();

        private readonly ValueDescriptionGroupAttribute _groupDescriptionAttribute;
        /// <summary>
        /// 获取组描述特性
        /// </summary>
        public ValueDescriptionGroupAttribute GroupDescriptionAttribute
        {
            get { return _groupDescriptionAttribute; }
        }

        private readonly IExtendDescription _extend;

        /// <summary>
        /// 组标识
        /// </summary>
        private readonly object _groupId;
        /// <summary>
        /// 组标识
        /// </summary>
        public object GroupId
        {
            get { return _groupId; }
        }


        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="extend">扩展描述接口</param>
        /// <param name="groupId">组标识</param>
        public ValueDescriptionGroup(IExtendDescription extend, object groupId)
        {
            this._groupId = groupId;
            this._extend = extend;
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="type">常量类型</param>
        /// <param name="groupId">组标识</param>
        public ValueDescriptionGroup(Type type, object groupId)
        {
            this._groupId = groupId;

            Type valueDescriptionGroupAttributeType = typeof(ValueDescriptionGroupAttribute);
            object[] attrObjArr = type.GetCustomAttributes(valueDescriptionGroupAttributeType, false);


            if (attrObjArr == null || attrObjArr.Length == 0)
            {
                this._groupDescriptionAttribute = null;
                this._extend = null;
            }
            else
            {
                this._groupDescriptionAttribute = (ValueDescriptionGroupAttribute)attrObjArr[0];
                if (this._groupDescriptionAttribute.ExtendDescriptionType != null)
                {
                    this._extend = (IExtendDescription)Activator.CreateInstance(this._groupDescriptionAttribute.ExtendDescriptionType);
                }
                else
                {
                    this._extend = null;
                }
            }


            FieldInfo[] fieldInfoArr = type.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public | BindingFlags.FlattenHierarchy);
            Type ignoreAttributeType = typeof(IgnoreAttribute);
            Type displayNameAttributeType = typeof(DisplayNameAttribute);
            Type displayNameExAttributeType = typeof(DisplayNameExAttribute);
            Type descriptionAttributeType = typeof(DescriptionAttribute);

            Type valuieType = typeof(TValueType);
            TValueType value;
            ConstantValueItem item;
            string displayName, description;
            DisplayNameExAttribute displayNameExAttribute;

            DescriptionAttribute descriptionAtt;
            DisplayNameAttribute displayNameAtt;

            foreach (var fieldInfo in fieldInfoArr)
            {
                if (fieldInfo.FieldType != valuieType)
                {
                    //非string字段忽略
                    continue;
                }

                attrObjArr = fieldInfo.GetCustomAttributes(ignoreAttributeType, false);
                if (attrObjArr != null && attrObjArr.Length > 0)
                {
                    //标记了忽略特性
                    continue;
                }

                //key
                value = (TValueType)fieldInfo.GetValue(null);
                if (value == null)
                {
                    throw new ArgumentNullException($"常量字段\"{type.FullName}.{fieldInfo.Name}\"值为null.值为null的字段不能用于注册.如果确实需有字段值为null,可以添加\"{nameof(IgnoreAttribute)}\"我忽略该字段");
                }

                //DisplayNameExAttribute
                attrObjArr = fieldInfo.GetCustomAttributes(displayNameExAttributeType, true);
                if (attrObjArr == null || attrObjArr.Length == 0)
                {
                    //DescriptionAttribute
                    attrObjArr = fieldInfo.GetCustomAttributes(descriptionAttributeType, true);
                    if (attrObjArr != null && attrObjArr.Length > 0)
                    {
                        descriptionAtt = (DescriptionAttribute)attrObjArr[0];
                        description = descriptionAtt.Description;
                    }
                    else
                    {
                        descriptionAtt = null;
                        description = null;
                    }

                    //DisplayNameAttribute
                    attrObjArr = fieldInfo.GetCustomAttributes(displayNameAttributeType, true);
                    if (attrObjArr == null || attrObjArr.Length == 0)
                    {
                        displayNameAtt = null;
                        displayName = fieldInfo.Name;
                    }
                    else
                    {
                        displayNameAtt = (DisplayNameAttribute)attrObjArr[0];
                        displayName = displayNameAtt.DisplayName;
                    }
                }
                else
                {
                    displayNameExAttribute = (DisplayNameExAttribute)attrObjArr[0];
                    displayName = displayNameExAttribute.DisplayName;
                    description = displayNameExAttribute.Description;
                    descriptionAtt = null;
                    displayNameAtt = displayNameExAttribute;
                }

                item = new ConstantValueItem(displayName, description, value)
                {
                    DescriptionAtt = descriptionAtt,
                    DisplayNameAtt = displayNameAtt
                };
                if (!this._dic.TryAdd(value, item))
                {
                    throw new ApplicationException($"类型[{type.FullName}]字段值[{value}]重复");
                }
            }
        }



        /// <summary>
        /// 添加一个常量项
        /// </summary>
        /// <param name="item">新的常量项</param>
        /// <exception cref="ApplicationException"></exception>
        public void Add(ConstantValueItem item)
        {
            if (!this._dic.TryAdd((TValueType)item.Value, item))
            {
                throw new ApplicationException($"字段值[{item.Value}]重复");
            }
        }

        /// <summary>
        /// 修改一个常量项
        /// </summary>
        /// <param name="item">新的常量项</param>
        public void Set(ConstantValueItem item)
        {
            this._dic[(TValueType)item.Value] = item;
        }

        /// <summary>
        /// 移除一个常量项
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>移除结果</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool Remove(TValueType value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ConstantValueItem item;
            return this._dic.TryRemove(value, out item);
        }

        /// <summary>
        /// 移除一个常量项
        /// </summary>
        /// <param name="item">要移除的项</param>
        /// <returns>移除结果</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool Remove(ConstantValueItem item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            bool result = false;
            var removeItems = this._dic.Where(kv => { return kv.Value.Value == item; });
            foreach (var kv in removeItems)
            {
                this._dic.TryRemove(kv.Key, out item);
                result = true;
            }

            return result;
        }

        /// <summary>
        /// 移除一个常量项
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>移除结果</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public bool Remove(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ConstantValueItem item;
            return this._dic.TryRemove((TValueType)value, out item);
        }

        /// <summary>
        /// 清空值描述组
        /// </summary>
        public void Clear()
        {
            this._dic.Clear();
        }



        /// <summary>
        /// 检测集合中是否包含指定的值,包含返回true,不包含返回false
        /// </summary>
        /// <param name="item">要检测的项</param>
        /// <returns>包含返回true,不包含返回false</returns>
        public bool Contains(ConstantValueItem item)
        {
            return this._dic.Values.Contains(item);
        }


        /// <summary>
        /// 检测集合中是否包含指定的值,包含返回true,不包含返回false
        /// </summary>
        /// <param name="value">要检测的值</param>
        /// <returns>包含返回true,不包含返回false</returns>
        public bool ContainsValue(TValueType value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return this._dic.ContainsKey(value);
        }

        /// <summary>
        /// 检测集合中是否包含指定的值,包含返回true,不包含返回false
        /// </summary>
        /// <param name="value">要检测的值</param>
        /// <returns>包含返回true,不包含返回false</returns>
        public bool ContainsValue(object value)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return this._dic.ContainsKey((TValueType)value);
        }





        /// <summary>
        /// 获取根据值获取值描述项,获取成功返回true,失败返回false
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="item">值描述项</param>
        /// <returns>获取成功返回true,失败返回false</returns>
        public bool TryGetItem(TValueType value, out ConstantValueItem item)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return this._dic.TryGetValue(value, out item);
        }

        /// <summary>
        /// 获取根据值获取值描述项,获取成功返回true,失败返回false
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="item">值描述项</param>
        /// <returns>获取成功返回true,失败返回false</returns>
        public bool TryGetItem(object value, out ConstantValueItem item)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            return this._dic.TryGetValue((TValueType)value, out item);
        }




        /// <summary>
        /// 根据组标识和值获取值名称(获取成功返回值名称;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>值名称</returns>
        public string GetNameByValue(TValueType value)
        {
            string name;
            if (this.TryGetNameByValue(value, out name))
            {
                return name;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"对应的值\"{value}\"名称不存在");
            }
        }

        /// <summary>
        /// 尝试根据组标识和值获取值名称(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="name">值名称</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetNameByValue(TValueType value, out string name)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ConstantValueItem item;
            if (this._dic.TryGetValue(value, out item))
            {
                name = item.DisplayName;
                return true;
            }

            if (this._extend != null &&
                this._extend.TryGetName(value, this, out name))
            {
                return true;
            }

            name = null;
            return false;
        }

        /// <summary>
        /// 根据组标识和值获取值名称(获取成功返回值名称;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>值名称</returns>
        public string GetNameByValue(object value)
        {
            string name;
            if (this.TryGetNameByValue(value, out name))
            {
                return name;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"对应的值\"{value}\"名称不存在");
            }
        }


        /// <summary>
        /// 尝试根据组标识和值获取值名称(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="name">值名称</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetNameByValue(object value, out string name)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ConstantValueItem item;
            if (this._dic.TryGetValue((TValueType)value, out item))
            {
                name = item.DisplayName;
                return true;
            }

            if (this._extend != null &&
                this._extend.TryGetName(value, this, out name))
            {
                return true;
            }

            name = null;
            return false;
        }





        /// <summary>
        /// 根据组标识和值获取值描述(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>值描述</returns>
        public string GetDescriptionByValue(TValueType value)
        {
            string des;
            if (this.TryGetDescriptionByValue(value, out des))
            {
                return des;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"对应的值\"{value}\"描述不存在");
            }
        }

        /// <summary>
        /// 尝试根据组标识和值获取值描述(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="des">值描述</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetDescriptionByValue(TValueType value, out string des)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ConstantValueItem item;
            if (this._dic.TryGetValue(value, out item))
            {
                if (item.Description == null)
                {
                    if (this._extend != null &&
                        this._extend.TryGetDescription(value, this, out des))
                    {
                        return true;
                    }
                    else
                    {
                        des = item.DisplayName;
                        return true;
                    }
                }
                else
                {
                    des = item.Description;
                    return true;
                }
            }
            else
            {
                if (this._extend != null &&
                    this._extend.TryGetDescription(value, this, out des))
                {
                    return true;
                }
                else
                {
                    des = null;
                    return false;
                }
            }
        }

        /// <summary>
        /// 根据组标识和值获取值描述(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>值描述</returns>
        public string GetDescriptionByValue(object value)
        {
            string des;
            if (this.TryGetDescriptionByValue(value, out des))
            {
                return des;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"对应的值\"{value}\"描述不存在");
            }
        }


        /// <summary>
        /// 尝试根据组标识和值获取值描述(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="des">值描述</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetDescriptionByValue(object value, out string des)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            ConstantValueItem item;
            if (this._dic.TryGetValue((TValueType)value, out item))
            {
                if (item.Description == null)
                {
                    if (this._extend != null &&
                        this._extend.TryGetDescription(value, this, out des))
                    {
                        return true;
                    }
                    else
                    {
                        des = item.DisplayName;
                        return true;
                    }
                }
                else
                {
                    des = item.Description;
                    return true;
                }
            }
            else
            {
                if (this._extend != null &&
                    this._extend.TryGetDescription(value, this, out des))
                {
                    return true;
                }
                else
                {
                    des = null;
                    return false;
                }
            }
        }





        /// <summary>
        /// 根据名称获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="name">名称</param>
        /// <returns>值</returns>
        public TValueType GetValueByNameEx(string name)
        {
            TValueType value;
            if (this.TryGetValueByNameEx(name, out value))
            {
                return value;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"名称\"{name}\"对应的值不存在");
            }
        }

        /// <summary>
        /// 根据名称获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetValueByNameEx(string name, out TValueType value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            ConstantValueItem item = this._dic.Values.FirstOrDefault(t =>
            {
                return string.Equals(t.DisplayName, name);
            });
            if (item != null)
            {
                value = (TValueType)item.Value;
                return true;
            }
            else
            {
                object obj;
                if (this._extend != null &&
                    this._extend.TryGetValueByName(name, this, out obj))
                {
                    value = (TValueType)obj;
                    return true;
                }
                else
                {
                    value = default(TValueType);
                    return false;
                }
            }
        }



        /// <summary>
        /// 根据名称获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="name">名称</param>
        /// <returns>值</returns>
        public object GetValueByName(string name)
        {
            object value;
            if (this.TryGetValueByName(name, out value))
            {
                return value;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"名称\"{name}\"对应的值不存在");
            }
        }

        /// <summary>
        /// 根据名称获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetValueByName(string name, out object value)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            ConstantValueItem item = this._dic.Values.FirstOrDefault(t =>
            {
                return string.Equals(t.DisplayName, name);
            });
            if (item != null)
            {
                value = item.Value;
                return true;
            }
            else
            {
                if (this._extend != null &&
                    this._extend.TryGetValueByName(name, this, out value))
                {
                    return true;
                }
                else
                {
                    value = null;
                    return false;
                }
            }
        }






        /// <summary>
        /// 根据值描述获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="des">值描述</param>
        /// <returns>值</returns>
        public TValueType GetValueByDescriptionEx(string des)
        {
            TValueType value;
            if (this.TryGetValueByDescriptionEx(des, out value))
            {
                return value;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"描述\"{des}\"对应的值不存在");
            }
        }

        /// <summary>
        /// 根据值描述获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="des">值描述</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetValueByDescriptionEx(string des, out TValueType value)
        {
            if (des == null)
            {
                throw new ArgumentNullException(nameof(des));
            }

            ConstantValueItem item = this._dic.Values.FirstOrDefault(t =>
            {
                return string.Equals(t.Description, des);
            });
            if (item != null)
            {
                value = (TValueType)item.Value;
                return true;
            }
            else
            {
                object obj;
                if (this._extend != null &&
                    this._extend.TryGetValueByDescription(des, this, out obj))
                {
                    value = (TValueType)obj;
                    return true;
                }
                else
                {
                    value = default(TValueType);
                    return false;
                }
            }
        }

        /// <summary>
        /// 根据值描述获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="des">值描述</param>
        /// <returns>值</returns>
        public object GetValueByDescription(string des)
        {
            object value;
            if (this.TryGetValueByDescription(des, out value))
            {
                return value;
            }
            else
            {
                throw new ArgumentException($"组标识\"{this._groupId}\"描述\"{des}\"对应的值不存在");
            }
        }

        /// <summary>
        /// 根据值描述获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="des">值描述</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        public bool TryGetValueByDescription(string des, out object value)
        {
            if (des == null)
            {
                throw new ArgumentNullException(nameof(des));
            }

            ConstantValueItem item = this._dic.Values.FirstOrDefault(t =>
            {
                return string.Equals(t.Description, des);
            });
            if (item != null)
            {
                value = item.Value;
                return true;
            }
            else
            {
                if (this._extend != null &&
                    this._extend.TryGetValueByDescription(des, this, out value))
                {
                    return true;
                }
                else
                {
                    value = default(TValueType);
                    return false;
                }
            }
        }





        /// <summary>
        /// 获取名称数组
        /// </summary>
        /// <returns>类型所有定义常量值数组</returns>
        public string[] GetNames()
        {
            return this._dic.Values.ToArray().Select(t =>
            {
                return t.DisplayName;
            }).ToArray();
        }





        /// <summary>
        /// 获取指定类型值数组
        /// </summary>
        /// <returns>类型所有定义常量值数组</returns>
        public TValueType[] GetValuesEx()
        {
            return this._dic.Keys.ToArray();
        }

        /// <summary>
        /// 获取指定类型值数组
        /// </summary>
        /// <returns>类型所有定义常量值数组</returns>
        public object[] GetValues()
        {
            return this._dic.Keys.Select(t =>
            {
                return (object)t;
            }).ToArray();
        }


        /// <summary>
        /// 获取元素个数
        /// </summary>
        public int Count
        {
            get { return this._dic.Count; }
        }

        /// <summary>
        /// 获取当前集合是否是只读的
        /// </summary>
        public bool IsReadOnly
        {
            get { return false; }
        }

        /// <summary>
        /// 将当前集合拷贝到指定数组
        /// </summary>
        /// <param name="array"></param>
        /// <param name="arrayIndex"></param>
        public void CopyTo(ConstantValueItem[] array, int arrayIndex)
        {
            this._dic.Values.CopyTo(array, arrayIndex);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IEnumerator<ConstantValueItem> GetEnumerator()
        {
            return this._dic.Values.GetEnumerator();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        IEnumerator IEnumerable.GetEnumerator()
        {
            return this._dic.Values.GetEnumerator();
        }

    }


    /// <summary>
    /// 值描述组接口
    /// </summary>
    public interface IValueDescriptionGroup : ICollection<ConstantValueItem>
    {

        /// <summary>
        /// 获取组描述特性
        /// </summary>
        ValueDescriptionGroupAttribute GroupDescriptionAttribute { get; }

        /// <summary>
        /// 组标识
        /// </summary>
        object GroupId { get; }



        ///// <summary>
        ///// 添加一个常量项
        ///// </summary>
        ///// <param name="item">新的常量项</param>
        ///// <exception cref="ApplicationException"></exception>
        //void Add(ConstantValueItem item);

        /// <summary>
        /// 修改一个常量项
        /// </summary>
        /// <param name="item">新的常量项</param>
        void Set(ConstantValueItem item);

        /// <summary>
        /// 移除一个常量项
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>移除结果</returns>
        /// <exception cref="ArgumentNullException"></exception>
        bool Remove(object value);

        ///// <summary>
        ///// 清空值描述组
        ///// </summary>
        //void Clear();

        /// <summary>
        /// 检测集合中是否包含指定的值,包含返回true,不包含返回false
        /// </summary>
        /// <param name="value">要检测的值</param>
        /// <returns>包含返回true,不包含返回false</returns>
        bool ContainsValue(object value);

        /// <summary>
        /// 获取根据值获取值描述项,获取成功返回true,失败返回false
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="item">值描述项</param>
        /// <returns>获取成功返回true,失败返回false</returns>
        bool TryGetItem(object value, out ConstantValueItem item);




        /// <summary>
        /// 根据组标识和值获取值名称(获取成功返回值名称;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>值名称</returns>
        string GetNameByValue(object value);

        /// <summary>
        /// 尝试根据组标识和值获取值名称(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="name">值名称</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        bool TryGetNameByValue(object value, out string name);





        /// <summary>
        /// 根据组标识和值获取值描述(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="value">值</param>
        /// <returns>值描述</returns>
        string GetDescriptionByValue(object value);

        /// <summary>
        /// 尝试根据组标识和值获取值描述(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="value">值</param>
        /// <param name="des">值描述</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        bool TryGetDescriptionByValue(object value, out string des);






        /// <summary>
        /// 根据名称获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="name">名称</param>
        /// <returns>值</returns>
        object GetValueByName(string name);

        /// <summary>
        /// 根据名称获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        bool TryGetValueByName(string name, out object value);





        /// <summary>
        /// 根据值描述获取值(获取成功返回值描述;失败抛出ArgumentException异常)
        /// </summary>
        /// <param name="des">值描述</param>
        /// <returns>值</returns>
        object GetValueByDescription(string des);

        /// <summary>
        /// 根据值描述获取值(获取成功返回true;失败返回false)
        /// </summary>
        /// <param name="des">值描述</param>
        /// <param name="value">值</param>
        /// <returns>获取成功返回true;失败返回false</returns>
        bool TryGetValueByDescription(string des, out object value);





        /// <summary>
        /// 获取名称数组
        /// </summary>
        /// <returns>类型所有定义常量值数组</returns>
        string[] GetNames();

        /// <summary>
        /// 获取指定类型值数组
        /// </summary>
        /// <returns>类型所有定义常量值数组</returns>
        object[] GetValues();


    }

}
